//
//  AMBaseViewController.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 01/07/16.
//  Copyright (c) 2016 WeiDu Energy Tech. All rights reserved.
//

#import "HOBaseViewController.h"
#import "HOUtils.h"
#import "HOUIMgr.h"
#import "Logger.h"
#import "HOLoginViewController.h"
#import "HOConstants.h"
#import "HOAppDataModule.h"
#import "HOAppController.h"
#import "HOQuickReportViewController.h"
#import "HOMyViewController.h"
#import "HOTableViewCell.h"
#import "HOEditTableViewCell.h"
#import "HONavigationController.h"
#import "HOButton.h"
#include <sys/socket.h> // Per msqr
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#import "HOQuickReportViewController.h"
#import "HOMyViewController.h"
#import "HOMessageViewController.h"
#import "Logger.h"
#import "HOGlobalData.h"
#import "HOJPushHandler.h"

#pragma mark
#pragma mark ----- UINavigationBar



#define kUrlScheme      @"shenoutranslater" // 这个是你定义的 URL Scheme，支付宝、微信支付和测试模式需要。

#define kWaiting          NSLocalizedString(@"正在获取支付凭据,请稍后...", @"正在获取支付凭据,请稍后...")
#define kNote             NSLocalizedString(@"提示", @"提示")
#define kConfirm          NSLocalizedString(@"确定", @"提示")
#define kErrorNet         NSLocalizedString(@"网络错误", @"网络错误")
#define kResult           NSLocalizedString(@"支付结果：%@", @"支付结果：")
@interface HOBaseViewController()
{
	UIView		*requestAgainView;
	HOButton	*requestAgainBtn;
	UILabel		*requestFailedReasonLbl;
	UILabel 	*backTitleLbl;
	UIAlertView* mAlert;
	UIButton  	*maskViewBtn;
}
@property(nonatomic, retain)NSString *channel;
@property(nonatomic, retain)NSMutableArray *currentScreenReuqestActionList;

@end

@implementation HOBaseViewController
@synthesize isPaySuccess;
@synthesize navTitle;
//@synthesize isBelongLoginScreen;
- (id)initWithModule:(HO_MODULE_TYPE)type
{
    if(self = [super init])
    {
        moduleType = type;
        [self bindController];
		self.currentScreenReuqestActionList = [[[NSMutableArray alloc] init] autorelease];
    }
    return self;
}

- (void)initRecordActiveView
{
}

- (id)init
{
	return [self initWithModule:HO_MODULE_TYPE_APP];
}

- (void)checkVersion
{
}

- (void)popupUpdateVersion
{
	HOAlertView *amAlertView = [[HOAlertView alloc] initWithTitle:nil
														  message:@"有新版本发布哦!"
														 delegate:self
												cancelButtonTitle:NSLocalizedString(@"忽略", @"忽略")
												otherButtonTitles:NSLocalizedString(@"立即去更新", @"立即去更新"), nil];
	amAlertView.tag = [kHO_DIALOG_NEWVERSION integerValue];
	[amAlertView show];
	[amAlertView release];
}

- (void)bindController
{
    controller = [[HOUIMgr sharedInstance] getController:moduleType];
    dataModule = [controller getDataModule];
}

-(void)viewDidLoad
{
    LogInf(@"-------------------%@----viewDidLoad-----------------", NSStringFromClass([self class]));

    [super viewDidLoad];
    hintView = [[HOLoadingView alloc]initForHint];
    loadingView = [[HOLoadingView alloc]init];
    [self.view setBackgroundColor:MAIN_BG_COLOR];
    [self bindController];
    [controller addListener:self];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    titleLabelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    titleLabelButton.frame = CGRectMake(0, 0, 150, 44);
    titleLabelButton.titleLabel.textAlignment = NSTextAlignmentCenter;
//    titleLabelButton.layer.borderWidth = 1;
    titleLabelButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [titleLabelButton addTarget:self action:@selector(didTapTitleView) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = titleLabelButton;
    entityDic = [[NSMutableDictionary alloc] init];
}

- (void)setNavigationItemTitle:(NSString *)title
{
	if(isTestingMode)
	{
		[titleLabelButton setTitle:[NSString stringWithFormat:@"%@(测试)", title] forState:UIControlStateNormal];
	}
	else
	{
		[titleLabelButton setTitle:title forState:UIControlStateNormal];
	}
}
- (void)startRequest
{
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//	[loadingView setText: NSStringFromClass([self class])];
    LogInf(@"+++++++++++++++++++++++++%@:++++++++++++++viewWillAppear+++++++++++", NSStringFromClass([self class]));
    [self.tabBarController.tabBar setTintColor:MAIN_TEXT_COLOR];
	self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [controller addListener:self];
	;
    [self updateLayout];
    if([self.navigationController.viewControllers count] == 1)
    {
        self.navigationItem.backBarButtonItem = nil;
        self.navigationItem.leftBarButtonItem = nil;
    }
    [HOUIMgr sharedInstance].currentScreen = self;
    [HOUIMgr sharedInstance].currentViewController = self;
    [self.view setBackgroundColor:MAIN_BG_COLOR];
    if([[HOUIMgr sharedInstance].currentViewController isKindOfClass:[HOQuickReportViewController class]]
//       || [[HOUIMgr sharedInstance].currentViewController isKindOfClass:[HOMessageViewController class]]
       || [[HOUIMgr sharedInstance].currentViewController isKindOfClass:[HOMyViewController class]])
    {
        if([HOGlobalData sharedInstance].needHandlePushMessage)
        {
//            [self.tabBarController setSelectedIndex:2];
        }
    }
	if(!self.navigationItem.hidesBackButton)
	{
		self.navigationItem.hidesBackButton = YES;
//		[self displayBackButtonItem];
		[self displayBackButtonItemWithImagePath:@"navigator_btn_back"];
	}
}

- (int)getIntFromVersion:(NSString *)version
{
    NSArray *array = [version componentsSeparatedByString:@"."];
    int versionValue = 0;
    for(int i = 0; i < [array count]; i++)
    {
        if(i == 0)
        {
            versionValue = versionValue + [[array objectAtIndex:0] intValue] * 1000;
        }
        else if(i == 1)
        {
            versionValue = versionValue + [[array objectAtIndex:1] intValue] * 100;
        }
        else if(i == 2)
        {
            versionValue = versionValue + [[array objectAtIndex:2] intValue];
        }
    }
    return versionValue;
    
}
- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated];
//	[self resetTableViewFrame];
	if(isRegisterKeyboard)
	{
		[self registerKeyboard];
	}
	
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    if(timeoutTimer != nil)
    {
        [timeoutTimer invalidate];
        timeoutTimer = nil;
	}
	[self unregisterKeyboard];

}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self hideKeyboard];
	[self unregisterTapGesture];
}

//- (void)udpateTableView
//{
//    
//    if(baseTableview)
//    {
//        CGFloat stautHeight = self.tabBarController.tabBar.hidden ? self.tabBarController.tabBar.frame.size.height : 0;
//        
//        baseTableview.frame = CGRectMake(0,
//                                         0,
//                                         self.view.frame.size.width,
//                                         self.view.frame.size.height + stautHeight);
//    }
//}

- (void)updateLayout
{
//    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = NO;
    CGFloat statusBarHeight =  [UIApplication sharedApplication].isStatusBarHidden ? 0 : [HOUtils getStatusBarHeight];
  
//    LogInf(@"self.tabBarController.tabBar.isHidden:%@", self.tabBarController.tabBar.isHidden ? @"YES" : @"NO");
    CGFloat tabBarHeight = self.tabBarController.tabBar.isHidden ? 0 : self.tabBarController.tabBar.frame.size.height;
    
    CGFloat navBarHeight = self.navigationController.navigationBar.isHidden ? 0 : self.navigationController.navigationBar.frame.size.height;

    if(baseTableview)
    {
        baseTableview.frame = CGRectMake(0,
                                   0,
                                   [HOUtils getScreenWidth],
                                   [HOUtils getScreenHeight] - statusBarHeight - tabBarHeight - navBarHeight - 0);
    }
}

- (NSString *)getTextFromTextField:(UITextField *)textField
{
    return [[textField text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
#pragma mark - -- getInputBox view --
- (UITextField *)getInputBox:(NSString *)pleaceHolder
{
    
    UITextField *inputBox = [[[UITextField alloc]init] autorelease];
    inputBox.placeholder = pleaceHolder;
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HO_HORIZONAL_PADDING, 20)];
    inputBox.leftView = paddingView;
    [paddingView release];
    inputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
    [inputBox setBackgroundColor:[UIColor whiteColor]];
    inputBox.font = [UIFont systemFontOfSize:CELL_FONT_SIZE];
    inputBox.contentHorizontalAlignment = UIControlContentVerticalAlignmentCenter;
    inputBox.textColor = UIColorFromRGB(0x333333);
    inputBox.layer.cornerRadius = 5;
    return inputBox;
}
#pragma mark - -- search view --
- (void)initSearchView
{
    searchView = [[HOSearchView alloc]
                  initWithFrame:CGRectMake(0,
                                           0,
                                           self.view.frame.size.width,
                                           self.view.frame.size.height - [HOUtils getStatusBarHeight] - 49)];
	searchView.delegate = self;
    [searchView setTableViewDataSource:self];
    [searchView setTableViewDelegate:self];
    [self.view addSubview:searchView];
    [[searchView getSearchBar] setBackgroundColor:MAIN_COLOR_NORMAL];
    
}
- (void)openSearchView
{
    if(searchView)
        [searchView openSearchView];
}

- (void)searchStatusDidChange:(HO_SEARCH_STATUS)status
{
    
    if(baseTableview)
    {
        [baseTableview reloadData];
    }
    
//    self.navigationController.navigationBar.hidden = (status != HO_SEARCH_CLOSED);
}

- (NSString *)getTrimingCharaFromTextField:(UITextField *)textField
{
    NSString *content = [[textField text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if(content == nil)
        content = @"";
    return content;
}

- (NSString *)getTrimingCharaFromTextView:(UITextView *)textField
{
	NSString *content = [[textField text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//	if(content == nil || content.length == 0)
//		content = @"无";
	return content;
}
#pragma mark - -- UIGesture
- (void)registerTapGesture
{
//    [self unregisterKeyboard];
    tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
    [self.view addGestureRecognizer:tapRecognizer];
    [self.navigationController.view addGestureRecognizer:tapRecognizer];
    [self.navigationController.navigationBar addGestureRecognizer:tapRecognizer];
    
    if(baseTableview)
    {
        [baseTableview addGestureRecognizer:tapRecognizer];
    }
    tapRecognizer.delegate = self;

}
- (void)unregisterTapGesture
{
    if(tapRecognizer)
    {
        [self.view removeGestureRecognizer:tapRecognizer];
        [self.navigationController.view removeGestureRecognizer:tapRecognizer];
        [self.navigationController.navigationBar removeGestureRecognizer:tapRecognizer];
        if(baseTableview)
        {
            [baseTableview removeGestureRecognizer:tapRecognizer];
        }
        tapRecognizer.delegate = nil;
        [tapRecognizer release];
        tapRecognizer = nil;
    }
}

- (void)didReceiveMemoryWarning
{
	
}

- (void)didTapTitleView
{
    [self hideKeyboard];
}
- (void)handleTapFrom:(UITapGestureRecognizer *)gesture
{
    [self hideKeyboard];
}

- (void) hideKeyboard
{
    if(searchView)
    {
        [[searchView getSearchBar] resignFirstResponder];
        [[searchView getSearchBar] endEditing:YES];
    }
	
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    // 输出点击的view的类名
//    LogInf(@"%@", NSStringFromClass([touch.view class]));
    
    // 若为UITableViewCellContentView（即点击了tableViewCell），则不截获Touch事件
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
        return NO;
    }
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UIButton"]) {
        return NO;
    }
//    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITextField"]) {
//        return NO;
//    }
    
    return (![[[touch view] class] isSubclassOfClass:[UIControl class]]);
//    return YES;
}

- (void)gotoSearchKey:(NSString *)key
{
	
}

#pragma mark get Verify code

#pragma mark - -- tableview --

- (void)initNoDataView
{
    if(self.noResultView)
        return;
    self.noResultView = [[[UIView alloc]
                    initWithFrame:CGRectMake(0,
                                             (self.view.frame.size.height - 93 - 37) / 2 - 64,
                                             self.view.frame.size.width,
                                             93 + 37)] autorelease];
	UIImage *img = [UIImage imageNamed:@"icon_empty"];
    UIImageView *imgView = [[[UIImageView alloc]
                            initWithFrame:CGRectMake((self.view.frame.size.width - img.size.width) / 2,
                                                     0,
                                                     img.size.width,
                                                     img.size.height)] autorelease];
    imgView.image = img;
    [self.noResultView addSubview:imgView];
    UILabel *lbl = [[[UILabel alloc]
                             initWithFrame:CGRectMake(0,
                                                      93 + 15,
                                                      self.view.frame.size.width,
                                                      22)] autorelease];
    lbl.textAlignment = NSTextAlignmentCenter;
    lbl.textColor = UIColorFromRGB(0x333333);
    lbl.font = [HOUtils fontWithSize:20];
    lbl.text = NSLocalizedString(@"暂时没有相关数据", @"暂时没有相关数据");
    [self.noResultView addSubview:lbl];
    self.noResultView.hidden = YES;
    [self.view addSubview:self.noResultView];
}

- (void)updateNoResultView:(NSInteger)count
{
	self.noResultView.hidden = count > 0;
	baseTableview.hidden = count == 0;
}

- (void)showNoDataView:(BOOL)show
{
	self.noResultView.hidden = !show;
	baseTableview.hidden = show;
}

- (void)initTableView
{
    if(self.tableViewDataList == nil)
        self.tableViewDataList = [[NSMutableArray alloc] init];
    [self initNoDataView];
	[self initRequestAgainView];
    baseTableview = [[HOTableView alloc]initWithFrame:CGRectMake(0,
                                                                 0,
                                                                 self.view.frame.size.width,
                                                                 self.view.frame.size.height)
                                                style:UITableViewStyleGrouped];
//    baseTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [baseTableview setBackgroundColor:MAIN_BG_COLOR];
    baseTableview.delaysContentTouches = NO;
	baseTableview.estimatedSectionHeaderHeight = 0;
	baseTableview.estimatedSectionFooterHeight = 0;
//	[baseTableview setAutoresizesSubviews:YES];
    baseTableview.delegate = self;
    baseTableview.dataSource = self;
//    baseTableview.layer.borderWidth = 2;
    baseTableview.sectionFooterHeight = 0;
	baseTableview.separatorColor = TEXT_GRAY_DARK_dbdbdb;
    [self.view addSubview:baseTableview];
}


- (void)resetTableViewFrame
{
	keyboardType = KB_HIDEN;
	keyboardSize = CGSizeMake(keyboardSize.width, 0);
	baseTableview.frame = CGRectMake(self.view.frame.origin.x,
									 baseTableview.frame.origin.y,
									 self.view.frame.size.width,
									 self.view.frame.size.height - 0 - baseTableview.frame.origin.y);
}

#pragma mark - -- init pickerView
- (void)didClickMask:(id)sender
{
	[self showPickerView:NO];
}
- (void)initPickerView
{
    
    pickerPanelView = [[UIView alloc]
                       initWithFrame:CGRectMake(0,
                                                self.view.frame.size.height,
                                                self.view.frame.size.width,
                                                260)];
	maskViewBtn = [[UIButton alloc] initWithFrame:self.view.frame];

	[maskViewBtn addTarget:self action:@selector(didClickMask:) forControlEvents:UIControlEventTouchUpInside];
	maskViewBtn.alpha = 0;
	[maskViewBtn setBackgroundColor:[UIColor blackColor]];
	[self.view addSubview:maskViewBtn];
	maskViewBtn.hidden = YES;
    pickerViewImp = [[UIPickerView alloc]
                  initWithFrame:CGRectMake(0,
                                           44,
                                           self.view.frame.size.width,
                                           216)];
    
    
    pickerViewImp.delegate = self;
    pickerViewImp.dataSource = self;
    [pickerViewImp setBackgroundColor:[UIColor whiteColor]];
    [pickerPanelView addSubview:pickerViewImp];
    pickerViewImp.showsSelectionIndicator = YES;
    
    UIView *toolBar = [[UIView alloc]initWithFrame:CGRectMake(-1, 0, self.view.frame.size.width + 2, 44)];
    [toolBar setBackgroundColor:UIColorFromRGB(0xf5f5f7)];
    toolBar.layer.borderWidth = [HOUtils defaultOnePixelConversion];
    toolBar.layer.borderColor = UIColorFromRGB(0xe3e2e3).CGColor;
    
    //创建工具栏
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmBtn.frame = CGRectMake(toolBar.frame.size.width - 80 - 2 * HO_HORIZONAL_PADDING,
                                  7,
                                  80,
                                  30);
    [confirmBtn setTitle:NSLocalizedString(@"确定", @"确定") forState:UIControlStateNormal];
    [confirmBtn addTarget:self action:@selector(didPickDone:) forControlEvents:UIControlEventTouchUpInside];
    [toolBar addSubview:confirmBtn];
    [confirmBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [confirmBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [confirmBtn setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(HO_HORIZONAL_PADDING,
                                 7,
                                 80,
                                 30);
    [cancelBtn setTitle:NSLocalizedString(@"关闭", @"关闭") forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(closePickerView:) forControlEvents:UIControlEventTouchUpInside];
    [toolBar addSubview:cancelBtn];
    [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
    
    
    [pickerPanelView addSubview:toolBar];
    [self.view addSubview:pickerPanelView];
    [toolBar release];
}



- (void)didPickDone:(id)sender
{
    [self showPickerView:NO];
}

- (void)reloadPickViewData
{
    [pickerViewImp reloadAllComponents];
}

- (void)openPickerVIew:(id)sender
{
    [self showPickerView:YES];
    
}
- (void)closePickerView:(id)sender
{
    [self showPickerView:NO];
}

- (void)showPickerView:(BOOL)show
{
    if(show)
    {
		maskViewBtn.hidden = NO;
        pickerPanelView.alpha = 1;
        [UIView animateWithDuration:0.3 animations:^{
            pickerPanelView.frame = CGRectMake(0,
                                               self.view.frame.size.height - 260,
                                               pickerViewImp.frame.size.width,
                                               pickerViewImp.frame.size.height);
			maskViewBtn.alpha = 0.4;
		}];
    }
    else
    {
        
        [UIView animateWithDuration:0.2 animations:^{
            pickerPanelView.frame = CGRectMake(0,
                                               self.view.frame.size.height,
                                               pickerViewImp.frame.size.width,
                                               pickerViewImp.frame.size.height);
            pickerPanelView.alpha = 0;
			maskViewBtn.alpha = 0;
		}completion:^(BOOL completed) {
			maskViewBtn.hidden = YES;
		}];
    }

}
- (void)resetPickerView
{
    pickerPanelView.frame = CGRectMake(0,
                                       self.view.frame.size.height,
                                       pickerViewImp.frame.size.width,
                                       pickerViewImp.frame.size.height);
    pickerPanelView.alpha = 0;
}

#pragma mark
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    [self hideKeyboard];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 0;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return 0;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return @"";
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    pickerViewSelectRow = row;
}

#import "HOQuickReportViewController.h"
#pragma mark
#pragma mark - -- loading
- (void)showLoadingView:(BOOL)show
{
    if(show)
    {
		self.view.userInteractionEnabled = NO;
		[loadingView show:self.view];
    }
    else
    {
		self.view.userInteractionEnabled = YES;
        [loadingView hide];
    }
}

#pragma mark - -- keyboard --
- (void)registerKeyboard
{
    isRegisterKeyboard = YES;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardFrameDidChange:) name:UIKeyboardDidChangeFrameNotification object:nil];
    
}

- (void)unregisterKeyboard
{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardDidHideNotification object:nil];
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardDidChangeFrameNotification object:nil];
}

#pragma mark - -- navigation bar --

- (void)hideBackBtn
{
	[self displayLeftButtonItemWithTitle:@""];
}
- (void)displayBackButtonItem
{
    UIBarButtonItem *newBackButton = nil;
    if(IS_LESSTHAN_IOS8)
    {
        
        newBackButton = [[UIBarButtonItem alloc] initWithTitle:@""
                                                         style:UIBarButtonItemStylePlain
                                                        target:self
                                                        action:@selector(goBack)];
    }
    else
    {
        
        newBackButton = [[UIBarButtonItem alloc] initWithTitle:@""
                                                         style:UIBarButtonItemStyleBordered
														target:self
														action:@selector(goBack)];
    }
	[newBackButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
										   [UIFont systemFontOfSize:14], NSFontAttributeName,
										   [UIColor whiteColor], NSForegroundColorAttributeName,
										   nil] forState:UIControlStateNormal];
	
    [[self navigationItem] setBackBarButtonItem:newBackButton];
    [newBackButton release];
}

- (void)displayLeftButtonItemWithTitle:(NSString *)leftBtnTitle
{
	UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithTitle:leftBtnTitle style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonItemDidClick)];
	[leftBtn setTintColor:[UIColor whiteColor]];
	[leftBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
									  [UIFont systemFontOfSize:14], NSFontAttributeName,
									  [UIColor whiteColor], NSForegroundColorAttributeName,
									  nil]
							forState:UIControlStateNormal];
	
	[self.navigationItem setLeftBarButtonItem:leftBtn];
}

- (void)displayRightButtonItemWithTitle:(NSString *)rightBtnTitle
{
//    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
//    
//    [right setFrame:CGRectMake(0, 2, self.view.frame.size.width / 2, 28)];
////    [right sizeToFit];
//    [right setTitle:rightBtnTitle forState:UIControlStateNormal];
//    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
////    [right setBackgroundColor:[UIColor clearColor]];
//	right.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
//    [right addTarget:self action:@selector(rightButtonItemDidClick) forControlEvents:UIControlEventTouchUpInside];
//	UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:right];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]
								 initWithTitle:rightBtnTitle
								 style:UIBarButtonItemStylePlain
								 target:self
								 action:@selector(rightButtonItemDidClick)];
    [rightBtn setTintColor:[UIColor whiteColor]];
	[rightBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
										[UIFont systemFontOfSize:14], NSFontAttributeName,
										[UIColor whiteColor], NSForegroundColorAttributeName,
										nil]
							  forState:UIControlStateNormal];
    [self.navigationItem setRightBarButtonItem:rightBtn];
}

- (void)displayLeftButtonItemWithImagePath:(NSString *)imagePath
{
	UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
	
	[left setFrame:CGRectMake(0, 2, 28, 28)];
	[left setImage:[UIImage imageNamed:imagePath]  forState:UIControlStateNormal];
	[left addTarget:self action:@selector(leftButtonItemDidClick) forControlEvents:UIControlEventTouchUpInside];
	
	
	UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:left];
	[self.navigationItem setLeftBarButtonItem:leftButton];
	[leftButton release];
}
- (void)displayBackButtonItemWithImagePath:(NSString *)imagePath
{
	
    UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
	
	UIImage *img = [UIImage imageNamed:imagePath];
	[left setImage:img forState:UIControlStateNormal];
	[left setFrame:CGRectMake(0, 2, img.size.width, img.size.height)];
	backTitleLbl = [[UILabel alloc] initWithFrame:CGRectMake(img.size.width + 6,
															 (img.size.height - 22) / 2,
															 100,
															 22)];
	self.navigationItem.hidesBackButton = YES;
	backTitleLbl.textColor = [UIColor whiteColor];
//	[left addSubview:backTitleLbl];
	self.navigationItem.backBarButtonItem.title = @"";
	[left setTitle: NSLocalizedString(@"", @"") forState:UIControlStateNormal];
	[left addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
//	[left addTarget:self action:@selector(updateLeftButtonTitle) forControlEvents:UIControlEventTouchDown];
//	[left addTarget:self action:@selector(updateLeftButtonToNormal) forControlEvents:UIControlEventTouchUpOutside];
	
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:left];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    [leftButton release];
}

- (void)displayRightButtomItemWithTitle:(NSString *)rightBtnTitle
{
	//    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
	//
	//    [right setFrame:CGRectMake(0, 2, self.view.frame.size.width / 2, 28)];
	////    [right sizeToFit];
	//    [right setTitle:rightBtnTitle forState:UIControlStateNormal];
	//    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	////    [right setBackgroundColor:[UIColor clearColor]];
	//	right.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
	//    [right addTarget:self action:@selector(rightButtonItemDidClick) forControlEvents:UIControlEventTouchUpInside];
	//	UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:right];
	UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]
								 initWithTitle:rightBtnTitle
								 style:UIBarButtonItemStylePlain
								 target:self
								 action:@selector(rightButtonItemDidClick)];
	[rightBtn setTintColor:[UIColor whiteColor]];
	[rightBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
									  [UIFont systemFontOfSize:14], NSFontAttributeName,
									  [UIColor whiteColor], NSForegroundColorAttributeName,
									  nil]
							forState:UIControlStateNormal];
	[self.navigationItem setRightBarButtonItem:rightBtn];
}

- (void)displayLeftButtomItemWithImagePath:(NSString *)imagePath
{
	UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
	
	[left setFrame:CGRectMake(0, 2, 28, 28)];
	[left setImage:[UIImage imageNamed:imagePath]  forState:UIControlStateNormal];
	[left addTarget:self action:@selector(leftButtonItemDidClick) forControlEvents:UIControlEventTouchUpInside];
	
	
	UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:left];
	[self.navigationItem setLeftBarButtonItem:leftButton];
	[leftButton release];
}
- (void)displayBackButtomItemWithImagePath:(NSString *)imagePath
{
	UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
	
	UIImage *img = [UIImage imageNamed:imagePath];
	[left setImage:img forState:UIControlStateNormal];
	[left setFrame:CGRectMake(0, 2, img.size.width, img.size.height)];
	backTitleLbl = [[UILabel alloc] initWithFrame:CGRectMake(img.size.width + 6,
															 (img.size.height - 22) / 2,
															 100,
															 22)];
	backTitleLbl.textColor = [UIColor whiteColor];
	backTitleLbl.text = @"";
	//	[left addSubview:backTitleLbl];
	[left setTitle: @"" forState:UIControlStateNormal];
	[left addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
	//	[left addTarget:self action:@selector(updateLeftButtonTitle) forControlEvents:UIControlEventTouchDown];
	//	[left addTarget:self action:@selector(updateLeftButtonToNormal) forControlEvents:UIControlEventTouchUpOutside];
	
	
	UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:left];
	[self.navigationItem setLeftBarButtonItem:leftButton];
	[leftButton release];
}

- (void)updateLeftButtonTitle
{
	backTitleLbl.textColor = TEXT_GRAY_COLOR;
}

- (void)updateLeftButtonToNormal
{
	backTitleLbl.textColor = [UIColor whiteColor];
}

- (void)displayLeftButtonItemWithButton:(UIButton *)btn
{
    [btn addTarget:self action:@selector(leftButtonItemDidClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [self.navigationItem setRightBarButtonItem:leftButton];
    [leftButton release];
}

- (void)displayRightButtonItemWithButton:(UIButton *)btn
{
    [btn addTarget:self action:@selector(rightButtonItemDidClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    [self.navigationItem setRightBarButtonItem:leftButton];
    [leftButton release];
}

- (void)leftButtonItemDidClick
{
    [self goBack];
}

- (void)rightButtonItemDidClick
{
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
    [controller removeListener:self];
}
#pragma mark - -- hint view --
- (void)hideHintView
{
    [hintView stopTimer:nil];
}

- (void)popupHintView:(NSString *)content
{
    [self popupHintView:content inTime:1.0];

}


- (void)popupHintView:(NSString *)content inTime:(double)time needCallback:(BOOL)needCallback
{
	
    CGSize size0 = [content sizeWithFont:[UIFont systemFontOfSize:14]];
    
    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat x = (screenSize.width - size0.width - 20)/2;
    
    //    (screenSize.height - 216 - size0.height)/2 - 64,
    hintView.layer.borderWidth = [HOUtils defaultOnePixelConversion];
    if(keyboardType == KB_SHOWEN)
    {
        hintView.frame = CGRectMake(x,
                                    self.view.frame.size.height - keyboardSize.height - size0.height - 40 - 64 - 49,
                                    size0.width + 20,
                                    30);
    }
    else
    {
        hintView.frame = CGRectMake(x,
                                    (self.view.frame.size.height - size0.height) / 2,
                                    size0.width + 20,
                                    30);
//        LogInf(@"x:%f, y:%f, w:%f", x, hintView.frame.origin.y, size0.width + 20);
    }
    [hintView show:self.view content:content displayTime:time];

    if(timeoutTimer != nil)
    {
        [timeoutTimer invalidate];
        timeoutTimer = nil;
    }
    
    if(needCallback)
    {
		self.view.userInteractionEnabled = NO;
        timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:time
                                                        target:self
                                                      selector:@selector(hintTimeout:)
                                                      userInfo:nil
                                                       repeats:NO];
        
    }
}

- (void)hintDidHide
{
}
- (void)hintTimeout:(NSTimer *)timer
{
    [timeoutTimer invalidate];
    timeoutTimer = nil;
    [self hintDidHide];
}
- (void)popupHintView:(NSString *)content inTime:(double)time
{
    [self popupHintView:content inTime:time needCallback:NO];
}

#pragma mark - -- keyboard event detect --
- (void)onKeyboardDidShow:(NSNotification *)notification
{
    keyboardType = KB_SHOWEN;
    [self updateSelfViewPosition];
    
}

- (void)onKeyboardDidHide:(NSNotification *)notification
{
    keyboardType = KB_HIDEN;
    [self updateSelfViewPosition];
}

- (void)onKeyboardWillShow:(NSNotification *)notification
{
//    if(!keyboardPopupedBefore)
//    {
//        tableViewY = baseTableview.frame.origin.y;
//        tableViewY
//    }
    keyboardType = KB_SWITCHING2SHOW;
    [self updateSelfViewPosition];
    [hintView hide];
}

- (void)onKeyboardWillHide:(NSNotification *)notification
{
    keyboardType = KB_SWITCHING2HIDE;
    [self updateSelfViewPosition];
    [hintView hide];
}

- (void)onKeyboardFrameDidChange:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    
    // Get the origin of the keyboard when it's displayed.
    
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    
    // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.
    
    CGRect keyboardRect = [aValue CGRectValue];
    keyboardSize = keyboardRect.size;
    [self updateSelfViewPosition];
    
}


- (void)updateSelfViewPosition
{
    CGFloat keyboardHeight = 0;
    if(keyboardType == KB_SWITCHING2SHOW || keyboardType == KB_SHOWEN)
    {
        if(keyboardSize.height == 0)
        {
			keyboardHeight = IS_MORETHAN_IOS8 ? 252 : 216;
        }
        else
            keyboardHeight = keyboardSize.height;
    }
    else
    {
        keyboardHeight = 0;
    }

    [UIView animateWithDuration:.25f
                     animations:^
     {
         //params set : (YES|NO, YES);
         
         baseTableview.frame = CGRectMake(self.view.frame.origin.x,
                                      baseTableview.frame.origin.y,
                                          self.view.frame.size.width,
                                          self.view.frame.size.height - keyboardHeight - baseTableview.frame.origin.y);
     }
                     completion:^(BOOL finished)
     {
         if(keyboardType == KB_HIDEN)
         {
             baseTableview.frame = CGRectMake(self.view.frame.origin.x,
                                              baseTableview.frame.origin.y,
                                              self.view.frame.size.width,
                                              self.view.frame.size.height - 0 - baseTableview.frame.origin.y);
         }
         else
         {
             
             baseTableview.frame = CGRectMake(self.view.frame.origin.x,
                                              baseTableview.frame.origin.y,
                                              self.view.frame.size.width,
                                              self.view.frame.size.height - keyboardHeight - baseTableview.frame.origin.y);
         }
     }];
}

#pragma mark - -- version check
- (void)didReceiveVersion:(HOBaseResponseEntity *)response
{
    if([HOGlobalData sharedInstance].isPopedUpAlertForVersion)
    {
        return;
    }
//	return;
    [HOGlobalData sharedInstance].isPopedUpAlertForVersion = YES;
    NSString *releasedVersion = [[response.dataNode objectForKey:@"Update"] objectForKey:@"Ios"];
    LogInf(@"releasedVersion:%@", releasedVersion);
//    releasedVersion = @"1.0.1";
    NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    LogWar(@"currentVersion:%@", currentVersion);
    int releasedVersionValue = [self getIntFromVersion:releasedVersion];
    int currentVersionValue = [self getIntFromVersion:currentVersion];
    LogWar(@"releasedVersionValue:%d", releasedVersionValue);
    LogWar(@"currentVersionValue:%d", currentVersionValue);
    if(releasedVersionValue > currentVersionValue)
    {
		[self popupUpdateVersion];
    }
    
}

- (void)cleanup
{
}

- (void)tokenInvalideRemind
{
	HOAlertView *alert =
	[[HOAlertView alloc] initWithTitle: @"警告"
							   message: NSLocalizedString(@"登陆信息失效, 请重新登陆!", @"登陆信息失效, 请重新登陆!")
							  delegate: self
					 cancelButtonTitle:@"关闭"
					 otherButtonTitles:@"重新登陆", nil];
	alert.tag = [kHO_DIALOG_TokenInvalide integerValue];
	[alert show];
	[alert release];
//	[[HOUIMgr sharedInstance] logout];
//	[self sendCommand:kHO_CMD_Token_invalide data:NSLocalizedString(@"登陆信息失效, 请重新登陆!", @"登陆信息失效, 请重新登陆!")];
}

#pragma mark - -- HOViewControllerDelegate impelment
- (void)didReceiveCommand:(NSString *)action data:(id)data
{
    if([action isEqualToString:kHO_ACTION_Logout])
	{
		[self cleanup];
	}
	else if([action isEqualToString:kHO_CMD_RCLoginOtherDevice])
	{
		[self tokenInvalideRemind];
	}
	else if([action isEqualToString:kHO_CMD_RCTokenInvalide])
	{
		[self tokenInvalideRemind];
	}
	else if([action isEqualToString:kHO_CMD_OpenMessageFromUrgency])
	{
	}
	if([action isEqualToString:kHO_CMD_Token_invalide])
	{
		[self popupHintView:data inTime:3];
	}
}

- (void)requestDidSuccessWithResponse:(HOBaseResponseEntity *)response
{
}

- (void)didReceiveResponse:(HOBaseResponseEntity *)response
{
	NSString *action = response.action;
//	if(action == nil || ![self.currentScreenReuqestActionList containsObject:action])
//	{
//		return;
//	}
	if([response.action isEqualToString:kHO_ACTION_AppVersion]
	   || [response.action isEqualToString:kHO_ACTION_Logout])
		return;
	if([response isRequestDone])
    {
        [self showLoadingView:NO];
        self.view.userInteractionEnabled = YES;
		if(requestAgainView)
			requestAgainView.hidden = YES;
        isRequesting = NO;
        
        if([response.action isEqualToString:kHO_ACTION_AppVersion])
        {
            [self didReceiveVersion:response];
		}
		[self requestDidSuccessWithResponse:response];
    }
    else if(response.baseRequest.status == HO_REQUEST_STATUS_DOING)
    {
        if([response.action isEqualToString:kHO_ACTION_AppVersion])
            return;
        isRequesting = YES;
        [self showLoadingView:YES];
        [self hideKeyboard];
		
//		NSString *content = [NSString stringWithFormat:@"%@:%d", NSLocalizedString(@"正在加载数据", @"正在加载数据"), response.baseRequest.progress, @"%"];
		NSString *content = [NSString stringWithFormat:@"%@", NSLocalizedString(@"正在加载数据", @"正在加载数据")];
		[loadingView setText:content];
        self.view.userInteractionEnabled = NO;
    }
    else if(response.baseRequest.status == HO_REQUEST_STATUS_FAILED)
    {
        [self showLoadingView:NO];
        self.view.userInteractionEnabled = YES;
        isRequesting = NO;
		[self requestDidFaildWithResponse:response];


        if([response getOperation] == OPERATION_NETWORK_DOWN)
		{
			if(requestAgainView)
			{
				[self requestFialedByNetworkDown:response.baseRequest withReason:[response getErrorMessage]];
				return;
			}
			else
			{
				[self netWorkDown:response];
				return;
			}
		}
		else if([response getOperation] == OPERATION_LOGIN_AGAIN)
		{
			[self loginPromote:response];
		}
		else
		{
			[self requestFailedPromote:response];
		}

    }
    else
	{
	}
}

- (void)requestDidFaildWithResponse:(HOBaseResponseEntity *)response
{
	self.view.userInteractionEnabled = YES;
}
- (void)requestFailedPromote:(HOBaseResponseEntity *)response
{
//	NSLog(@"[HOUIMgr sharedInstance].currentScreen:%@", [HOUIMgr sharedInstance].currentScreen);
    if([HOUIMgr sharedInstance].currentScreen != self)
    {
        return;
    }
	if([response.action isEqualToString:kHO_ACTION_UploadJpush])
	{
		return;
	}
	NSString *otherBtn = nil;
	if([response getOperation] == OPERATION_REQUEST_AGAIN)
	{
		otherBtn = NSLocalizedString(@"再次请求", @"再次请求");
	}
	else
	{
		otherBtn = nil;
	}
    HOAlertView *amAlertView = [[HOAlertView alloc] initWithTitle:nil
                                             message:[response getErrorMessage]
                                            delegate:self
                                   cancelButtonTitle:NSLocalizedString(@"关闭", @"关闭")
                                   otherButtonTitles:otherBtn, nil];
    amAlertView.data = response;
    amAlertView.tag = [kHO_DIALOG_REQUEST_FAILED integerValue];
    [amAlertView show];
    [amAlertView release];
}

- (void)netWorkDown:(HOBaseResponseEntity *)response
{
    
    if([HOUIMgr sharedInstance].currentScreen != self)
    {
        return;
    }
    HOAlertView *amAlertView = [[HOAlertView alloc] initWithTitle:NSLocalizedString(@"请求失败", @"请求失败")
                                                    message:[response getErrorMessage]
                                                   delegate:self
                                          cancelButtonTitle:NSLocalizedString(@"关闭", @"关闭")
                                          otherButtonTitles:NSLocalizedString(@"再次请求", @"再次请求"), nil];
    amAlertView.data = response.baseRequest;
    amAlertView.tag = [kHO_DIALOG_NETWORK_DOWN integerValue];
    [amAlertView show];
    [amAlertView release];
}
- (void)loginPromote:(HOBaseResponseEntity *)response
{
    HOBaseController *appController = [[HOUIMgr sharedInstance] getController:HO_MODULE_TYPE_APP];
    [((HOAppDataModule *)[appController getDataModule]) clearLockedPasswordWithUserId:[[HOUIMgr sharedInstance] getUserId]];
    [baseTableview reloadData];
    
    if([HOUIMgr sharedInstance].currentScreen != self)
    {
        return;
    }
	[self tokenInvalideRemind];
}



- (void)alertViewCancel:(HOAlertView *)alertView
{
	[alertView alertDidClose];
}

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
	if([alertView isKindOfClass:[HOAlertView class]])
	{
		[((HOAlertView *)alertView) alertDidClose];
	}
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	if([alertView isKindOfClass:[HOAlertView class]])
	{
		[((HOAlertView *)alertView) alertDidClose];
	}
	if(buttonIndex == 0)
	{
		HOAlertView *view = (HOAlertView *)alertView;
		if(![view.data isKindOfClass:[HOBaseResponseEntity class]])
		{
			[self goBack];
			return;
		}
		HOBaseResponseEntity *reponse = ((HOBaseResponseEntity *)view.data);
		if(reponse.getOperation == OPERATION_GO_BACK)
		{
			[self goBack];
			return;
		}
	}
	
    if(alertView.tag == 2300)
    {
        if(buttonIndex == 1)
        {
//            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            [[HOJPushHandler sharedInstance] openPushNotification:YES];
            if(baseTableview)
            {
                [baseTableview reloadData];
            }
        }
        return;
    }
    else if(alertView.tag == [kHO_DIALOG_TokenInvalide integerValue])
    {
        //Login
        if(buttonIndex == 1)
        {
            [[HOUIMgr sharedInstance] logout];
        }
        else
        {
            //            [self goBack];
//            [[HOUIMgr sharedInstance] logout];
        }
        return;
    }
    else if(alertView.tag == [kHO_DIALOG_NEWVERSION integerValue])
    {
        //Login
        if(buttonIndex == 1)
        {
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/app/id1298972877"]];
        }
        else
        {
//            [self goBack];
        }
        return;
    }
    else if(alertView.tag == [kHO_DIALOG_NETWORK_DOWN integerValue])
    {
        //网络问题再次请求
        if(buttonIndex == 1)
        {
            HOAlertView *view = (HOAlertView *)alertView;
            [[HOUIMgr sharedInstance] sendRequest:((HOBaseResponseEntity *)view.data).baseRequest];
        }
        return;
    }
	else if(alertView.tag == [kHO_DIALOG_NETWORK_DOWN integerValue])
	{
		//网络问题再次请求
		HOAlertView *view = (HOAlertView *)alertView;
		if(buttonIndex == 1)
		{
			[[HOUIMgr sharedInstance] sendRequest:((HOBaseResponseEntity *)view.data).baseRequest];
		}
		else
		{
			
		}
		return;
	}
    else if(alertView.tag == [kHO_DIALOG_REQUEST_FAILED integerValue])
    {
        //请求失败，再次请求
        HOAlertView *view = (HOAlertView *)alertView;
        if(buttonIndex == 1)
        {
            [[HOUIMgr sharedInstance] sendRequest:((HOBaseResponseEntity *)view.data).baseRequest];
        }
        else
        {
            
        }
    }
	else if(alertView.tag == [kHO_DIALOG_G0BACK integerValue])
	{
		[self goBack];
	}
	
}
#pragma mark - -- UITableViewDelegate/UITableViewDataResource implement methods
- (void)initTableViewFooterViewWithTitle:(NSString *)title
{
	baseTableview.tableFooterView = [self getFooterViewWithTitle:title];
}
- (UIView *)getFooterViewWithTitle:(NSString *)title
{
	UIView *view = [[[UIView alloc]initWithFrame:CGRectMake(0,
															0,
															baseTableview.frame.size.width,
															110)] autorelease];
	UIButton *footerBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
	footerBtn.frame = CGRectMake(HO_HORIZONAL_PADDING,
								 IS_IPHONE_4_SCREEN ? 5 : HO_HORIZONAL_PADDING,
								  baseTableview.frame.size.width - 2 * HO_HORIZONAL_PADDING,
								  40);
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
	[footerBtn setTintColor:[UIColor whiteColor]];
	[footerBtn setTitle:title forState:UIControlStateNormal];
	[footerBtn addTarget:self action:@selector(didClickFooterButton:) forControlEvents:UIControlEventTouchUpInside];
	[footerBtn setBackgroundImage:[HOUtils createImageWithColor:MAIN_COLOR_NORMAL forView:footerBtn] forState:UIControlStateNormal];
	[footerBtn setBackgroundImage:[HOUtils createImageWithColor:TEXT_GRAY_DARK_dbdbdb forView:footerBtn] forState:UIControlStateDisabled];
	footerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	footerBtn.layer.cornerRadius = 3;
	footerBtn.tag = 111;
	[footerBtn.layer setMasksToBounds:YES];
	[view addSubview:footerBtn];
	return view;
}

- (void)initTableViewHeaderViewWithTitle:(NSString *)title
{
	UIView *view = [[[UIView alloc]initWithFrame:CGRectMake(0,
															0,
															baseTableview.frame.size.width,
															110)] autorelease];
	UIButton *footerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	footerBtn.frame = CGRectMake(HO_HORIZONAL_PADDING,
								 IS_IPHONE_4_SCREEN ? 5 : HO_HORIZONAL_PADDING,
								 baseTableview.frame.size.width - 2 * HO_HORIZONAL_PADDING,
								 40);
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
	[footerBtn setTintColor:[UIColor whiteColor]];
	[footerBtn setTitle:title forState:UIControlStateNormal];
	[footerBtn addTarget:self action:@selector(didClickFooterButton:) forControlEvents:UIControlEventTouchUpInside];
	[footerBtn setBackgroundImage:[HOUtils createImageWithColor:MAIN_COLOR_NORMAL forView:footerBtn] forState:UIControlStateNormal];
	[footerBtn setBackgroundImage:[HOUtils createImageWithColor:TEXT_GRAY_DARK_dbdbdb forView:footerBtn] forState:UIControlStateDisabled];
	footerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
	[footerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	footerBtn.layer.cornerRadius = 3;
	[footerBtn.layer setMasksToBounds:YES];
	[view addSubview:footerBtn];
	baseTableview.tableHeaderView = view;
}

- (void)didClickFooterButton:(UIButton *)btn
{
	
}

- (void)didClickHeaderButton:(UIButton *)btn
{
	
}
#pragma mark - -- UITableViewDelegate/UITableViewDataResource implement methods
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
	return 12;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 64;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 0;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 12;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *AMBaseTableViewCellIdentifier = @"HOTableViewCell";
    HOTableViewCell *cell = (HOTableViewCell *)[tableView dequeueReusableCellWithIdentifier:AMBaseTableViewCellIdentifier];
    if(cell == nil)
    {
        cell = [[[HOTableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier: AMBaseTableViewCellIdentifier] autorelease];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}
#pragma mark

- (HOEditTableViewCell *)tableView:(UITableView *)tableView cellForEditRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *AMBaseTableViewCellIdentifier = @"HOTableViewCell";
	HOEditTableViewCell *cell = (HOEditTableViewCell *)[tableView dequeueReusableCellWithIdentifier:AMBaseTableViewCellIdentifier];
	if(cell == nil)
	{
		cell = [[[HOEditTableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault
				 reuseIdentifier: AMBaseTableViewCellIdentifier] autorelease];
	}
	return cell;
}
#pragma mark -- tool


- (NSNumber *)numberWithInt:(int)intValue
{
    return [NSNumber numberWithInt:intValue];
}

#pragma mark -- dealloc
-(void)dealloc
{
	
//	LogInf(@"-------------------%@----dealloc-----------------", NSStringFromClass([self class]));
	
	[self.currentScreenReuqestActionList removeAllObjects];
	self.currentScreenReuqestActionList = nil;
	self.tableViewDataList = nil;
//    LogInf(@"baseViewCtrl dealloc1");
    [controller removeListener:self];
    [entityDic removeAllObjects];
    [entityDic release];
    [titleLabelButton release];
	if(backTitleLbl)
	{
		[backTitleLbl release];
		backTitleLbl = nil;
	}
//    LogInf(@"baseViewCtrl dealloc2");
    if(searchView)
    {
		[HOUtils removeFromSuperViewForViews:searchView];
        searchView.delegate = nil;
    }
    if(pickerViewImp)
	{
		[HOUtils removeFromSuperViewForViews:pickerViewImp];
        pickerViewImp.delegate = nil;
        pickerViewImp.dataSource = nil;
    }
	controller = nil;
	if(hintView)
	{
		[HOUtils removeFromSuperViewForViews:hintView];
		[hintView release];
		hintView = nil;
	}
    
//    LogInf(@"baseViewCtrl dealloc4");
	if(hintView)
	{
		[HOUtils removeFromSuperViewForViews:loadingView];
		[loadingView release];
		loadingView = nil;
	}
	if(tapRecognizer)
	{
		[self.navigationController.view removeGestureRecognizer:tapRecognizer];
		[self.view removeGestureRecognizer:tapRecognizer];
		[self.navigationController.navigationBar removeGestureRecognizer:tapRecognizer];
		if(baseTableview)
		{
			[baseTableview removeGestureRecognizer:tapRecognizer];
		}
		tapRecognizer.delegate = nil;
		[tapRecognizer release];
		tapRecognizer = nil;
	}
	if(baseTableview)
	{
		[HOUtils removeFromSuperViewForViews:baseTableview];
		[baseTableview release];
		baseTableview = nil;
	}
	self.tableViewDataList = nil;
	if(requestAgainBtn)
	{
		[HOUtils removeFromSuperViewForViews:requestAgainBtn];
		[requestAgainBtn release];
	}
	if(requestAgainView)
	{
		[HOUtils removeFromSuperViewForViews:requestAgainView];
		[requestAgainView release];
	}
	if(requestFailedReasonLbl)
	{
		[HOUtils removeFromSuperViewForViews:requestFailedReasonLbl];
		[requestFailedReasonLbl release];
	}
	
	
    LogInf(@"baseViewCtrl dealloc6");
	
	
	
    [super dealloc];
}

- (void)requestFialedByNetworkDown:(HOBaseRequestEntity *)request withReason:(NSString *)reasen
{
	requestAgainView.hidden = NO;
	requestAgainBtn.data = request;
	requestFailedReasonLbl.text = reasen;
	requestFailedReasonLbl.frame = CGRectMake(0,
											  requestAgainBtn.frame.size.height + requestAgainBtn.frame.origin.y + 27,
											  self.view.frame.size.width,
											  100);
	[requestFailedReasonLbl sizeToFit];
	requestFailedReasonLbl.frame = CGRectMake(0,
											  requestAgainBtn.frame.size.height + requestAgainBtn.frame.origin.y + 27,
											  self.view.frame.size.width,
											  requestFailedReasonLbl.frame.size.height);
	[self.view bringSubviewToFront:requestAgainView];
}
#pragma mark
- (void)initRequestAgainView
{
	if(requestAgainView)
		return;
	requestAgainView = [[UIView alloc]
				  initWithFrame:CGRectMake(0,
										   0,
										   self.view.frame.size.width,
										   self.view.frame.size.height)];
	[requestAgainView setBackgroundColor:MAIN_BG_COLOR];
	
	requestAgainBtn = [[HOButton buttonWithType:UIButtonTypeCustom] retain];
	requestAgainBtn.frame = CGRectMake((self.view.frame.size.width - 89) / 2,
									(self.view.frame.size.height - 89) / 2 - 89,
									89,
									89);
	[requestAgainBtn setBackgroundImage:[UIImage imageNamed:@"icon_refresh"] forState:UIControlStateNormal];
	[requestAgainBtn addTarget:self action:@selector(requestAgain:) forControlEvents:UIControlEventTouchUpInside];
	[requestAgainView addSubview:requestAgainBtn];
	
	requestFailedReasonLbl = [[UILabel alloc]
					initWithFrame:CGRectMake(0,
												requestAgainBtn.frame.size.height + requestAgainBtn.frame.origin.y + 27,
												self.view.frame.size.width,
												100)];
	requestFailedReasonLbl.textColor = TEXT_GRAY_COLOR;
	requestFailedReasonLbl.text = NSLocalizedString(@"网络不给力, 点击刷新", @"网络不给力, 点击刷新");
	requestFailedReasonLbl.textAlignment = NSTextAlignmentCenter;
	requestFailedReasonLbl.font = [UIFont systemFontOfSize:15];
	requestFailedReasonLbl.numberOfLines = 0;
	[requestAgainView addSubview:requestFailedReasonLbl];
	requestAgainView.hidden = YES;
	[self.view addSubview:requestAgainView];
}

- (void)requestAgain:(id)sender
{
	requestAgainView.hidden = YES;
	HOButton *btn = (HOButton *)sender;
	HOBaseRequestEntity *request = btn.data;
	[controller sendRequestWithRequest:request];
}

- (void)showAlertWait
{
	mAlert = [[UIAlertView alloc] initWithTitle:kWaiting message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
	[mAlert show];
	UIActivityIndicatorView* aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
	aiv.center = CGPointMake(mAlert.frame.size.width / 2.0f - 15, mAlert.frame.size.height / 2.0f + 10 );
	[aiv startAnimating];
	[mAlert addSubview:aiv];
	[aiv release];
}

- (void)showAlertMessage:(NSString*)msg
{
	self.isPaySuccess = [msg isEqualToString:@"success"];
	NSString *content = nil;
	if(self.isPaySuccess)
	{
		content = NSLocalizedString(@"支付成功!", @"支付成功!");
	}
	else
	{
		content = NSLocalizedString(@"支付失败!", @"支付失败!");
	}
	mAlert = [[UIAlertView alloc] initWithTitle:kNote message:content delegate:self cancelButtonTitle:kConfirm otherButtonTitles:nil, nil];
	mAlert.tag = [kHO_DIALOG_G0BACK integerValue];
	[mAlert show];
}

- (void)hideAlert
{
	if (mAlert != nil)
	{
		[mAlert dismissWithClickedButtonIndex:0 animated:YES];
		[mAlert release];
		mAlert = nil;
	}
}

- (void)removeFromSuperViewForView:(UIView *)view
{
	if(!view)
		return;
	if([view isKindOfClass:[UIView class]] && [view superview])
	{
		[view removeFromSuperview];
	}
}
- (void)removeFromSuperViewForSubView:(UIView *)view, ...
{
	va_list args;
	va_start(args, view);
	if (view)
	{
		UIView *otherView;
		while ((otherView = va_arg(args, UIView *)))
		{
			//依次取得所有参数
			if(otherView)
			{
				[otherView removeFromSuperview];
			}
		}
	}
	va_end(args);
}
- (void)sendCommand:(NSString *)action data:(id)data
{
	[controller sendCommand:action data:data];
}

- (void)sendRequestWithParams:(NSDictionary *)dic
{
	NSString *action = [dic objectForKey:kHO_FIELD_Action];
	if(action)
	{
		if(![self.currentScreenReuqestActionList containsObject:action])
		{
			[self.currentScreenReuqestActionList addObject:action];
		}
	}
	[controller sendRequestWithParams:dic
					withModules:nil];
}



@end
